import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import streamlit as st

timesData = pd.read_csv("data/timesData.csv")

# rows = st.number_input("请输入显示的行数：",min_value=5,max_value=200)
rows = st.slider("请输入显示的行数：",min_value=5,max_value=200)

columns  = st.multiselect("请输入你要显示的列名：",timesData.columns)
if len(columns)==0:
    columns = ['country','teaching','world_rank','citations','university_name']

df = timesData.loc[:rows,columns]

st.dataframe(df)

# import graph objects as "go"
import plotly.graph_objs as go

mycolor1 = st.color_picker("请选择颜色：")
if mycolor1 is None:
    mycolor1 = 'rgba(16, 112, 2, 0.8)'


# Creating trace1
trace1 = go.Scatter(
                    x = df.world_rank,
                    y = df.citations,
                    mode = "lines",
                    name = "citations",
                    marker = dict(color =mycolor1  ),
                    text= df.university_name)
# Creating trace2
trace2 = go.Scatter(
                    x = df.world_rank,
                    y = df.teaching,
                    mode = "lines+markers",
                    name = "teaching",
                    marker = dict(color = 'rgba(80, 26, 80, 0.8)'),
                    text= df.university_name)
data = [trace1, trace2]
layout = dict(title = 'Citation and Teaching vs World Rank of Top 100 Universities',
              xaxis= dict(title= 'World Rank',ticklen= 5,zeroline= False)
             )
fig = dict(data = data, layout = layout)

st.plotly_chart(fig)
